home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / mac / Sample Code / QuickTime / QuickTimeIntro / Graphic Import⁄Export / Completed Lab / MultipleImages.c < prev    next >
Encoding:
Text File  |  2000-10-06  |  3.0 KB  |  91 lines  |  [TEXT/CWIE]

  1. // Graphics Importer and Exporter Samples
  2. // This example demonstrates how to display multiple images
  3. // Originally written by Sam Bushell for QuickTime "Live" '99
  4. // WWDC 2000 Introduction to QuickTime
  5.  
  6. #include "MacShell.h"
  7.  
  8. void MultipleImage( void )
  9. {
  10.     OSErr err = noErr;
  11.     Handle hOpenTypeList = NewHandle(0);
  12.     long  numTypes = 0;
  13.     FSSpec    theFSSpec;
  14.     GraphicsImportComponent importer = 0;
  15.     Rect naturalBounds, windowBounds;
  16.     WindowPtr window = NULL;
  17.     unsigned long imageCount, imageIndex;
  18.     ImageDescriptionHandle desc = NULL;
  19.     MatrixRecord matrix;
  20.  
  21.     BuildGraphicsImporterValidFileTypes( hOpenTypeList, &numTypes );
  22.     HLock( hOpenTypeList );
  23.     
  24.     err = GetOneFileWithPreview(numTypes, (OSTypePtr)*hOpenTypeList, &theFSSpec, NULL);
  25.     DisposeHandle( hOpenTypeList );
  26.     if ( err ) return;
  27.     
  28.     // locate and open a graphics importer component
  29.     err = GetGraphicsImporterForFile( &theFSSpec, &importer );
  30.     
  31.     // get the native size of the image associated with the importer
  32.     err = GraphicsImportGetNaturalBounds( importer, &naturalBounds );
  33.     windowBounds = naturalBounds;
  34.     OffsetRect( &naturalBounds, 10, 45 );
  35.     window = NewCWindow( NULL, &naturalBounds, "\pMultiple Images", true, documentProc, (WindowPtr)-1, true, 0);
  36.     
  37.     // set the graphics port for drawing
  38.     err = GraphicsImportSetGWorld( importer, GetWindowPort(window), NULL );
  39.     
  40.     // ask the graphics importer how many images there are in this file
  41.     err = GraphicsImportGetImageCount( importer, &imageCount );
  42.     
  43.     for( imageIndex = 1; imageIndex <= imageCount; imageIndex++ ) {    
  44.         // set the index value for the image we want to draw
  45.         err = GraphicsImportSetImageIndex( importer, imageIndex );
  46.         
  47.         // each image in the file can have different dimensions, depth, etc.
  48.         // if the image has an alpha, use StraightAlpha graphics mode to draw
  49.         err = GraphicsImportGetImageDescription( importer, &desc );
  50.         if( (*desc)->depth == 32 )
  51.             err = GraphicsImportSetGraphicsMode( importer, graphicsModeStraightAlpha, NULL );
  52.         else
  53.             err = GraphicsImportSetGraphicsMode( importer, ditherCopy, NULL );
  54.         DisposeHandle( (Handle)desc );
  55.         
  56.         // set up the matrix
  57.         SetIdentityMatrix( &matrix );
  58.         GraphicsImportGetDefaultMatrix( importer, &matrix );
  59.         err = GraphicsImportSetMatrix( importer, &matrix );
  60.  
  61.         SetPortWindowPort( window );
  62.         EraseRect( &windowBounds );
  63.         
  64.         // draw the image
  65.         err = GraphicsImportDraw( importer );
  66.  
  67.         pause();
  68.     }
  69.     
  70.     // draw the images again but this type don't erase
  71.     for( imageIndex = 2; imageIndex <= imageCount; imageIndex++ ) {
  72.         err = GraphicsImportSetImageIndex( importer, imageIndex );
  73.         
  74.         err = GraphicsImportGetImageDescription( importer, &desc );
  75.         if( (*desc)->depth == 32 )
  76.             err = GraphicsImportSetGraphicsMode( importer, graphicsModeStraightAlpha, NULL );
  77.         else
  78.             err = GraphicsImportSetGraphicsMode( importer, ditherCopy, NULL );
  79.         DisposeHandle( (Handle)desc );
  80.         
  81.         SetIdentityMatrix( &matrix );
  82.         GraphicsImportGetDefaultMatrix( importer, &matrix );
  83.         err = GraphicsImportSetMatrix( importer, &matrix );
  84.  
  85.         err = GraphicsImportDraw( importer );
  86.  
  87.         pause();
  88.     }
  89.  
  90.     CloseComponent( importer );
  91. }